﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace ShevaEngine.Core.Modules.Graphics.Foundation
{
    /// <summary>
    /// A screen plane used for most screen shaders.
    /// </summary>
    public class ScreenPlane
    {
        /// <summary>Singleton.</summary>
        public static readonly ScreenPlane Instance = new ScreenPlane();

        /// <summary>Vertex buffer.</summary>
        private VertexBuffer VertexBuffer;

        /// <summary>
        /// Constructor.
        /// </summary>
        public ScreenPlane()
        {
            VertexPositionTexture[] vertices = new[]
                {
                    new VertexPositionTexture(new Vector3(-1.0f, -1.0f, 0f), new Vector2(0, 1)),
                    new VertexPositionTexture(new Vector3(-1.0f, 1.0f, 0f),  new Vector2(0, 0)),
                    new VertexPositionTexture(new Vector3(1.0f, -1.0f, 0f),  new Vector2(1, 1)),
                    new VertexPositionTexture(new Vector3(1.0f, 1.0f, 0f),   new Vector2(1, 0)),
                };
            
            this.VertexBuffer = new VertexBuffer(
                ShevaEngine.Instance.GraphicsDevice, 
                typeof(VertexPositionTexture), vertices.Length, BufferUsage.WriteOnly);

            this.VertexBuffer.SetData(vertices);
        }

        /// <summary>
        /// Render a screen plane.
        /// </summary>
        public void Render()
        {
            ShevaEngine.Instance.GraphicsDevice.SetVertexBuffer(this.VertexBuffer);
            ShevaEngine.Instance.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
        }
    }
}
